package com.yan.demo;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class MethodTest8 {
    public static void main(String[] args) {
        // int count = 0;
        int[] luckArr = luckNumber();
        // int[] randomNumber = luckNumber();
        int[] useArr = userChoseNumber();
        judge(useArr, luckArr);
        // System.out.println("count = " + count++);
    }

    // 获取中奖号码的数组
    public static int[] luckNumber() {
        int[] arr = new int[7];
        // Random r = new Random();
        // boolean flag = true;
        int redNum, index = 0;
        // 随机数取红球
       /* for (int i = 0; i < arr.length - 1; i++) {
            num = r.nextInt(33) + 1;
            for (int j = 0; j < i; j++) {
                if (num == arr[j]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                arr[i] = num;
            } else {
                i--;
                flag = true;
            }
        }*/
        outer:
        while (true) {
            redNum = new Random().nextInt(33) + 1;
            inner:
            // 内循环判断是否有相同的值
            for (int i = 0; i < index; i++) {
                if (redNum == arr[i]) {
                    continue outer;
                }
            }
            // 程序走到这说明arr[0-index - 1]中没有相同的值
            // 将redNum存入数组中
            arr[index++] = redNum;
            // 判断当数组存满的时候跳出循环
            if (index == arr.length - 1) {
                break outer;
            }
        }
        // 随机数产生蓝球
        arr[arr.length - 1] = new Random().nextInt(16) + 1;
        return arr;
    }

    // 获取用户输入的数组
    public static int[] userChoseNumber() {
       /* int[] arr = new int[7];
        Scanner input = new Scanner(System.in);
        for (int i = 0; i < arr.length - 1; i++) {
            System.out.println("输入第" + (i + 1) + "个红球");
            arr[i] = input.nextInt();
        }
        System.out.println("输入一个蓝球");
        arr[6] = input.nextInt();
        return arr;*/
        int[] arr = new int[7];
        int redNum, index = 0;
        // 随机数取红球
       /* for (int i = 0; i < arr.length - 1; i++) {
            num = r.nextInt(33) + 1;
            for (int j = 0; j < i; j++) {
                if (num == arr[j]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                arr[i] = num;
            } else {
                i--;
                flag = true;
            }
        }*/
        outer:
        while (true) {
            System.out.println("请输入一个红色球");
            redNum = new Scanner(System.in).nextInt();
            if(redNum >33 || redNum < 1){
                System.err.println("输入的数据不合法！");
            }
            inner:
            // 内循环判断是否有相同的值
            for (int i = 0; i < index; i++) {
                if (redNum == arr[i]) {
                    System.err.println("输入的红球重复！");
                    continue outer;
                }
            }
            // 程序走到这说明arr[0-index - 1]中没有相同的值
            // 将redNum存入数组中
            arr[index++] = redNum;
            // 判断当数组存满的时候跳出循环
            if (index == arr.length - 1) {
                break outer;
            }
        }
        // 用户输入一个蓝球
        while (true) {
            System.out.println("输入一个蓝球");
            int bullBall = arr[arr.length - 1] = new Scanner(System.in).nextInt();
            if(bullBall <1 || bullBall >16){
                System.err.println("输入的数据不合法!");
                continue;
            }
            return arr;
        }
    }

    // 判断方法判断中奖情况
    public static void judge(int[] useArr, int[] luckArr) {
        int redBall = 0; // 红球中奖个数
        int bullBall = 0; // 蓝球中奖个数
        for (int i = 0; i < useArr.length - 1; i++) {
            for (int j = 0; j < luckArr.length - 1; j++) {
                if (useArr[i] == luckArr[j]) {
                    redBall++;
                }
            }
        }
        if (useArr[6] == luckArr[6]) {
            bullBall++;
        }
        System.out.println("中奖号码为:" + Arrays.toString(luckArr));
        System.out.println("中了" + redBall + "个红球," + bullBall + "个蓝球");
        if (redBall == 6 && bullBall == 1) {
            System.out.println("中1000万");
            // System.exit(0);
        } else if (redBall == 6 && bullBall == 0) {
            System.out.println("中500万");
            // System.exit(0);
        } else if (redBall == 5 && bullBall == 1) {
            System.out.println("中3000元");
        } else if ((redBall == 5 && bullBall == 0) || (redBall == 4 && bullBall == 1)) {
            System.out.println("中200");
        } else if ((redBall == 4 && bullBall == 0) || (redBall == 3 && bullBall == 1)) {
            System.out.println("中10元");
        } else if (redBall == 1 && bullBall < 3) {
            System.out.println("中5元");
        } else {
            System.out.println("没中奖");
        }
    }

}
